package com.citicup.backend.controller;

import com.citicup.backend.service.FundService.FundService;
import com.citicup.backend.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FundController {

    final FundService fundService;

    @Autowired
    public FundController(FundService fundService) {
        this.fundService = fundService;
    }

    @GetMapping("/showFundList")
    public ResponseVO showFundList() {
        return fundService.showFundList();
    }

    @GetMapping("/showFundList/{fundCode}")
    public ResponseVO showFund(@PathVariable String fundCode) {
        return fundService.showFundByFundCode(fundCode);
    }

    //测试用
    @GetMapping("/updateFund")
    //每日十七点更新
    @Scheduled(cron = "0 0 17 * * *")
    public void updateFundInfo() {
        fundService.updateFundInfo();
        fundService.calretrait();
        fundService.calfangcha();
    }

    //for testing stock
    @GetMapping("/updateStock")
    @Scheduled(cron = "0 0 17 * * *")
    public void updateStock() {
        fundService.updateStock();
    }

    //for testing zuidahuiche
    @GetMapping("/fuck")
    public void calretrait() { fundService.calretrait();}

    @GetMapping("/lhx")
    public void calfangcha() { fundService.calfangcha();}

    @GetMapping("/getHistoryFund")
    public void getHistory() {
        fundService.getHistory();
    }
}
